package com.ydd.controller.admin;

import com.ydd.dto.SysUserPageQueryDTO;
import com.ydd.entity.SysUser;
import com.ydd.result.Result;
import com.ydd.service.SysUserService;
import com.ydd.vo.SysUserPageQueryVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("sys_user")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    //分页
    @GetMapping("/list")
    public Result list(@RequestParam String login_name, String status, String phone, String page, String limit){
        //接收前端数据并封装在sysUserPageQueryDTO中
        SysUserPageQueryDTO sysUserPageQueryDTO = new SysUserPageQueryDTO(login_name,status,phone,page,limit);
        //调用sysUserServer中的分页方法
        SysUserPageQueryVO sysUserPageQueryVO = sysUserService.pageQuery(sysUserPageQueryDTO);
        //返回分页结果
        return Result.success(sysUserPageQueryVO);
    }

    //管理员添加
    @PostMapping("/add")

    public Result add(@RequestBody SysUser sysUser){
        //调用sysUserServer中的add方法
        sysUserService.add(sysUser);
        //返回响应结果
        return Result.success();
    }

    //管理员详情
    @GetMapping("/rowInfo")
    public Result<SysUser> rowInfo(@RequestParam String id){
        //打印日志
        log.info("管理员详情,员工id为:{}",id);
        //调用显示管理员详情的方法
        SysUser sysUser = sysUserService.rowInfo(id);
        //返回数据
        return Result.success(sysUser);
    }

    //删除
    @GetMapping("/del")
    public  Result del(@RequestParam String id){
        sysUserService.del(id);
        return Result.success();
    }

    //修改
    @PostMapping("/update")
    public Result update(@RequestBody SysUser sysUser){
        sysUserService.update(sysUser);
        return Result.success();
    }
}
